<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    
<template id="cpn">
    <div>
        <h2>子组件</h2>
    </div>
</template>


<div class="app">
    <cpn></cpn>
    <cpn ref="hgt"></cpn>
    <cpn></cpn>
<button @click="btnClick">按钮</button>
</div>


<script src="../vue.js" type="text/javascript" charset="utf-8">
</script>
    <script type="text/javascript">
        const app = new Vue({
            el:'.app',
            methods:{
                btnClick(){
                    console.log(this.$refs.hgt.name)
                    }
            },
            components: {
                cpn:{
                    templates:'#cpn',
                    data () {
                        return {
                            name:'子组件的name属性'
                        }
                    },
                    methods: {
                        showMessages(){
                            console.log('子组件中的showMessage方法');
                        }
                    }
                }
            }
        })

    </script>




</body>
</html>